package cn.group.service.impl;

import cn.group.dao.RoomDao;
import cn.group.dao.TeacherDao;
import cn.group.domain.Room;
import cn.group.domain.Teacher;
import cn.group.service.TeacherService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {
   private TeacherDao teacherDao;
    @Autowired
    public TeacherServiceImpl(TeacherDao teacherDao){
        this.teacherDao = teacherDao;
    }
    @Override
    public List<Teacher> getAll() {
        return teacherDao.queryAll();
    }

    @Override
    public PageInfo<Teacher> getTeacherByPage(Integer currentPage, Integer pagesize) {
        //pagehelper内部计算总共有多少页
        PageHelper.startPage(currentPage,pagesize);
        List<Teacher>teacherList = teacherDao.queryAll();
        PageInfo<Teacher>pageInfo = new PageInfo<>(teacherList);
        return pageInfo;
    }
/*添加教师*/
    @Override
    public boolean addOne(Teacher teacher) {
        int result = teacherDao.insertByTeacher(teacher);
        return result>0;
    }
/*修改教师信息*/
    @Override
    public boolean modifyOne(Teacher teacher) {
        int result = teacherDao.updateByTeacher(teacher);
        return result>0;
    }

    @Override
    public Teacher getOneById(Integer id) {
        Teacher teacher = teacherDao.queryById(id);
        return teacher;
    }

    @Override
    public boolean removeOne(Integer id) {
        int result = teacherDao.deleteByTeacher(id);
        return result>0;
    }

    @Override
    public Teacher queryByUsername(String username) {
        return teacherDao.queryByUsername(username);
    }
}
